﻿using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Lottery.Client.SL
{
    public class BetDataControl
    {
        public static ObservableCollection<BetData> BetDatas;

        public BetDataControl()
        {
           // BetDatas = new ObservableCollection<BetData>(new List<BetData>());
        }
        static BetDataControl()
        {
            BetDatas = new ObservableCollection<BetData>(new List<BetData>());
        }

        public static int InvestSumNum
        {
            get
            {
                int num = 0;
                int num2 = 0;
                if (!CulbViewMode.SelectGame.SelectGameMenu.SelectGameMode.PlayTypeName.Contains("?"))
                {
                    using (IEnumerator<BetData> enumerator = BetDatas.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BetData current = enumerator.Current;
                            if (num2 == 0)
                            {
                                num2 = current.InvestCount.Length;
                            }
                            num += current.InvestNum;
                        }
                        return num;
                    }
                }
                using (IEnumerator<BetData> enumerator2 = BetDatas.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        BetData current2 = enumerator2.Current;
                        if (num2 == 0)
                        {
                            num2 = current2.InvestCount.Length;
                        }
                        num += PublicFunction.GetDsNum(num2, current2.InvestCount);
                    }
                }
                return num;
            }
        }

        public static void AddBetData(int investNum, string investCount, double width)
        {
            var betData = new BetData();
            betData.InvestNum = investNum;
            betData.InvestCount = investCount;
            betData.Width = width;
            BetDatas.Add(betData);
        }

        public static void RemoveBetData(BetData bd)
        {
            BetDatas.Remove(bd);
        }

        public static void ClearBetData()
        {
            lock (BetDatas)
            {
                BetDatas.Clear();
            }
        }

        public static string GetInvestSumCount()
        {
            string text = "";
            using (IEnumerator<BetData> enumerator = BetDatas.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    BetData current = enumerator.Current;
                    text = text + current.InvestCount + "?";
                }
            }
            if (text.Length > 0)
            {
                text = text.Substring(0, text.Length - 1);
            }
            return text;
        }

        public static bool ContainsBetData(string data)
        {
            using (IEnumerator<BetData> enumerator = BetDatas.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    BetData current = enumerator.Current;
                    if (current.InvestCount == data)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
    }
}